package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCheck;
import com.ruoyi.system.service.ISysCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/check")
public class SysCheckController extends BaseController {
    @Autowired
    private ISysCheckService sysCheckService;

    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCheck check){
        startPage();
        List<SysCheck> list = sysCheckService.selectCheckList(check);
        return getDataTable(list);
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:check:add')")
    @Log(title = "检查费管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysCheck check)
    {
        check.setCreateBy(getUsername());
        return toAjax(sysCheckService.insertCheck(check));
    }

    @PreAuthorize("@ss.hasPermi('system:check:query')")
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable Long checkId)
    {
        return success(sysCheckService.selectCheckById(checkId));
    }

    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "检查费管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysCheck check)
    {
        check.setUpdateBy(getUsername());
        return toAjax(sysCheckService.updateCheck(check));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('system:check:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{checkIds}")
    public AjaxResult remove(@PathVariable long [] checkIds)
    {
        return toAjax(sysCheckService.deleteByIds(checkIds));
    }

    //查询所有检查信息
    @GetMapping("/all")
    public TableDataInfo list(){
        startPage();
        List<SysCheck> list = sysCheckService.selectAll();
        return getDataTable(list);
    }

    //按关键字查询检查信息
    @PostMapping("/keyword")
    public TableDataInfo keyword(@RequestBody String keyword){
        startPage();
        List<SysCheck> list = sysCheckService.selectByKeyword(keyword);
        return getDataTable(list);
    }


}
